/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.corespring.restaurant.dao.hibernate;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import org.corespring.restaurant.dao.PlatoMenuDao;
import org.corespring.restaurant.model.Platomenu;
import org.corespring.restaurant.model.PlatomenuId;

@Repository
public class PlatoMenuDaoHibernate extends HibernateDaoSupport implements PlatoMenuDao {

    @Autowired
    public PlatoMenuDaoHibernate(SessionFactory sessionFactory) {
		setSessionFactory(sessionFactory);
    }

    @Override
    public void guardarPlatoMenu(Platomenu platomenu) {
      getHibernateTemplate().saveOrUpdate(platomenu);
    }

    @Override
    public List<Platomenu> obtenerListaPlatosPorMenu(String idMenu) {
        List list = getHibernateTemplate().find(" from Platomenu where idmenu='" +idMenu+"' ");
        return list;
    }

    @Override
    public Platomenu obtenerPlatoByMenuAndPlato(String idMenu,String idPlato) {
        List<Platomenu> list = getHibernateTemplate().find(" from Platomenu where idmenu='" + idMenu + "' and idplato = '" + idPlato + "' ");
        if (list.size()>0){
            return list.get(0);
        }
        return null;
    }

    @Override
    public void eliminarPlatoMenu(String idMenu,String idPlato) {
        Platomenu platomenu = obtenerPlatoByMenuAndPlato(idMenu,idPlato);
        getHibernateTemplate().delete(platomenu);
    }

    @Override
    public List<Platomenu> obtenerListaPlatosPorMenu() {
        List list = getHibernateTemplate().find(" from Platomenu ");
        return list;
    }
    
}
